/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.biblio.persistencias;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Héctor <UFG>
 */
@Entity
@Table(name = "libro", catalog = "mydb", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Libro.findAll", query = "SELECT l FROM Libro l"),
    @NamedQuery(name = "Libro.findByLibId", query = "SELECT l FROM Libro l WHERE l.libId = :libId"),
    @NamedQuery(name = "Libro.findByLibIsbn", query = "SELECT l FROM Libro l WHERE l.libIsbn = :libIsbn"),
    @NamedQuery(name = "Libro.findByLibAnoPub", query = "SELECT l FROM Libro l WHERE l.libAnoPub = :libAnoPub"),
    @NamedQuery(name = "Libro.findByLibNumPag", query = "SELECT l FROM Libro l WHERE l.libNumPag = :libNumPag"),
    @NamedQuery(name = "Libro.findByLibEdicion", query = "SELECT l FROM Libro l WHERE l.libEdicion = :libEdicion"),
    @NamedQuery(name = "Libro.findByLibSinopsis", query = "SELECT l FROM Libro l WHERE l.libSinopsis = :libSinopsis"),
    @NamedQuery(name = "Libro.findByLibEstado", query = "SELECT l FROM Libro l WHERE l.libEstado = :libEstado"),
    @NamedQuery(name = "Libro.findByLibPalabraClave", query = "SELECT l FROM Libro l WHERE l.libPalabraClave = :libPalabraClave"),
    @NamedQuery(name = "Libro.findByLibValorReposicion", query = "SELECT l FROM Libro l WHERE l.libValorReposicion = :libValorReposicion")})
public class Libro implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "lib_id")
    private Integer libId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "lib_isbn", nullable = false, length = 15)
    private String libIsbn;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 4)
    @Column(name = "lib_ano_pub", nullable = false, length = 4)
    private String libAnoPub;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 4)
    @Column(name = "lib_num_pag", nullable = false, length = 4)
    private String libNumPag;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 15)
    @Column(name = "lib_edicion", nullable = false, length = 15)
    private String libEdicion;
    @Basic(optional = false)
    @NotNull
    @Lob
    @Column(name = "lib_foto", nullable = false)
    private byte[] libFoto;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "lib_sinopsis", nullable = false, length = 45)
    private String libSinopsis;
    @Basic(optional = false)
    @NotNull
    @Column(name = "lib_estado", nullable = false)
    private boolean libEstado;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "lib_palabra_clave", nullable = false, length = 45)
    private String libPalabraClave;
    @Size(max = 6)
    @Column(name = "lib_valor_reposicion", length = 6)
    private String libValorReposicion;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "autlibIdLib")
    private List<AutorLibro> autorLibroList;
    @JoinColumn(name = "lib_id_edi", referencedColumnName = "edi_id", nullable = false)
    @ManyToOne(optional = false)
    private Editorial libIdEdi;
    @JoinColumn(name = "lib_id_est1", referencedColumnName = "est_id", nullable = false)
    @ManyToOne(optional = false)
    private Estante libIdEst1;
    @JoinColumn(name = "lib_id_niv1", referencedColumnName = "estn_id", nullable = false)
    @ManyToOne(optional = false)
    private EstanteNivel libIdNiv1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "ejeIdLib")
    private List<Ejemplar> ejemplarList;

    public Libro() {
    }

    public Libro(Integer libId) {
        this.libId = libId;
    }

    public Libro(Integer libId, String libIsbn, String libAnoPub, String libNumPag, String libEdicion, byte[] libFoto, String libSinopsis, boolean libEstado, String libPalabraClave) {
        this.libId = libId;
        this.libIsbn = libIsbn;
        this.libAnoPub = libAnoPub;
        this.libNumPag = libNumPag;
        this.libEdicion = libEdicion;
        this.libFoto = libFoto;
        this.libSinopsis = libSinopsis;
        this.libEstado = libEstado;
        this.libPalabraClave = libPalabraClave;
    }

    public Integer getLibId() {
        return libId;
    }

    public void setLibId(Integer libId) {
        this.libId = libId;
    }

    public String getLibIsbn() {
        return libIsbn;
    }

    public void setLibIsbn(String libIsbn) {
        this.libIsbn = libIsbn;
    }

    public String getLibAnoPub() {
        return libAnoPub;
    }

    public void setLibAnoPub(String libAnoPub) {
        this.libAnoPub = libAnoPub;
    }

    public String getLibNumPag() {
        return libNumPag;
    }

    public void setLibNumPag(String libNumPag) {
        this.libNumPag = libNumPag;
    }

    public String getLibEdicion() {
        return libEdicion;
    }

    public void setLibEdicion(String libEdicion) {
        this.libEdicion = libEdicion;
    }

    public byte[] getLibFoto() {
        return libFoto;
    }

    public void setLibFoto(byte[] libFoto) {
        this.libFoto = libFoto;
    }

    public String getLibSinopsis() {
        return libSinopsis;
    }

    public void setLibSinopsis(String libSinopsis) {
        this.libSinopsis = libSinopsis;
    }

    public boolean getLibEstado() {
        return libEstado;
    }

    public void setLibEstado(boolean libEstado) {
        this.libEstado = libEstado;
    }

    public String getLibPalabraClave() {
        return libPalabraClave;
    }

    public void setLibPalabraClave(String libPalabraClave) {
        this.libPalabraClave = libPalabraClave;
    }

    public String getLibValorReposicion() {
        return libValorReposicion;
    }

    public void setLibValorReposicion(String libValorReposicion) {
        this.libValorReposicion = libValorReposicion;
    }

    @XmlTransient
    public List<AutorLibro> getAutorLibroList() {
        return autorLibroList;
    }

    public void setAutorLibroList(List<AutorLibro> autorLibroList) {
        this.autorLibroList = autorLibroList;
    }

    public Editorial getLibIdEdi() {
        return libIdEdi;
    }

    public void setLibIdEdi(Editorial libIdEdi) {
        this.libIdEdi = libIdEdi;
    }

    public Estante getLibIdEst1() {
        return libIdEst1;
    }

    public void setLibIdEst1(Estante libIdEst1) {
        this.libIdEst1 = libIdEst1;
    }

    public EstanteNivel getLibIdNiv1() {
        return libIdNiv1;
    }

    public void setLibIdNiv1(EstanteNivel libIdNiv1) {
        this.libIdNiv1 = libIdNiv1;
    }

    @XmlTransient
    public List<Ejemplar> getEjemplarList() {
        return ejemplarList;
    }

    public void setEjemplarList(List<Ejemplar> ejemplarList) {
        this.ejemplarList = ejemplarList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (libId != null ? libId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Libro)) {
            return false;
        }
        Libro other = (Libro) object;
        if ((this.libId == null && other.libId != null) || (this.libId != null && !this.libId.equals(other.libId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return libPalabraClave + " [" + libEdicion + ", " + libIdEdi.getEdiNombre() + "]";
    }
    
}
